package 分类.回溯;

import java.util.LinkedList;
import java.util.List;

/*
和求子集最大的不同是允许顺序不同存在


 */
public class 全排列 {
    static List<List<Integer>> res=new LinkedList<>();
    static LinkedList<Integer> track=new LinkedList<>();
    public static List<List<Integer>> permute(int[] nums) {
      back(nums,track);
      return res;
    }

    static void back(int[] nums,LinkedList<Integer> track){
        if(track.size()== nums.length){
            res.add(new LinkedList<>(track));
            return;
        }
        for (int i=0;i<nums.length;i++){
            if(track.contains(nums[i])) continue;
            track.add(nums[i]);
            back(nums,track);
            track.removeLast();
        }
    }

    public static void main(String[] args) {
        int[] nums={1,2,3};
        List<List<Integer>> res=permute(nums);
        for (List<Integer> re : res) {
            System.out.println(re);
        }
    }
}
